package com.example.lenovo.demo.presenter.listener;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.baidu.mapapi.map.OverlayOptions;
import com.example.lenovo.demo.MyApplication;
import com.example.lenovo.demo.model.Model;
import com.example.lenovo.demo.model.databean.CityBean;
import com.example.lenovo.demo.model.idatabean.IModel;
import com.example.lenovo.demo.model.idatabean.OnCitySuccess;
import com.example.lenovo.demo.presenter.adapter.CityRvAdapter;
import com.example.lenovo.demo.view.ifgview.ICityFirstActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/1/8.
 */

public class CityFirstActivityPresenter {
    private ICityFirstActivity iCityFirstActivity;
    private IModel iModel;
    private List<Object> list;
    private RecyclerView recyclerView;
    private Context context;
    private String id;
    private CityRvAdapter adapter;
    private CityBean.DataBean.DestinationBean destinationBean;
    private List<OverlayOptions> optionses;
    public CityFirstActivityPresenter(ICityFirstActivity ICityFirstActivity) {
        this.iCityFirstActivity = ICityFirstActivity;
        this.iModel=new Model();
        this.list=new ArrayList<>();
        this.destinationBean=new CityBean.DataBean.DestinationBean();
        list.add(destinationBean);
        this.context=iCityFirstActivity.getCityContext();
        this.recyclerView=iCityFirstActivity.getRecyclerView();
        this.id=iCityFirstActivity.getID();
        this.adapter=new CityRvAdapter(list,context);

    }
    /**
     * 实现控件的数据展示
     * */
    public void initData(){

        iCityFirstActivity.getProgressDialog().show();
        recyclerView.setLayoutManager((new LinearLayoutManager(context)));
        optionses=new ArrayList<>();
        iModel.sendCityBean(id, new OnCitySuccess() {
            @Override
            public void CitySuccess(CityBean cityBean) {
                List<CityBean.DataBean.GoodsBean> lists=cityBean.getData().getGoods();
                CityBean.DataBean.DestinationBean destinationBean=cityBean.getData().getDestination();
                destinationBean.setGoods(lists);
                destinationBean.setWikiDestinationBean(cityBean.getData().getWiki_destination());
                list.set(0,destinationBean);
                list.addAll(cityBean.getData().getSections());
                MyApplication.id=cityBean.getData().getWiki_destination().getId();
                recyclerView.setAdapter(adapter);
                iCityFirstActivity.getProgressDialog().dismiss();

            }

            @Override
            public void CityFailed() {

            }
        });
    }
}
